//
//  LGSportOrderDetailController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/6.
//  运动评估订单-详情

#import "LGSportOrderDetailController.h"
#import "LGOrderSportHeadView.h"
#import "LGOrderSportGoodsCell.h"
#import "LGOrderSportOrderCell.h"
@interface LGSportOrderDetailController ()<UITableViewDelegate,UITableViewDataSource>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)LGOrderSportHeadView *headView;
/**   */
@property (nonatomic , strong)NSDictionary *goodsDic;
/**   */
@property (nonatomic , strong)NSArray *titleArray;
/**   */
@property (nonatomic , strong)NSArray *contentArray;
@end

@implementation LGSportOrderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.goodsDic = @{};
    self.contentArray = @[@" ",@" ",@" "];
    self.titleArray = @[@"订单编号",@"订单时间",@"支付金额"];
    self.navigationView.title = @"订单详情";
    [self.view addSubview:self.tableView];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/mall/orderDetail" parameters:@{@"record_id":self.recordid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.headView.status = LGNSString(returnData[@"state"]);
            self.headView.statusName = LGNSString(returnData[@"state_name"]);
            self.headView.patientDic = returnData[@"patient"];
            self.goodsDic = returnData[@"goods"];
            self.contentArray = @[LGNSString(returnData[@"order"][@"order_sn"]),LGNSString(returnData[@"order"][@"create_time"]),[NSString stringWithFormat:@"%@ 元",returnData[@"order"][@"paid_amount"]]];
            [self.tableView reloadData];
        }
    } error:^(NSError *error) {
        
    }];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 1;
    }else{
        return 3;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        LGOrderSportGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"goodsCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.dataDic = self.goodsDic;
        return cell;
    }else{
        LGOrderSportOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"orderCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.title = self.titleArray[indexPath.row];
        cell.content = self.contentArray[indexPath.row];
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return (section == 0)?0.01:viewPix(50);
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(section == 0){
        return [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }else{
        LGCornerHeaderView *headView = [[LGCornerHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(50))];
        headView.backgroundColor = [UIColor clearColor];
        headView.topMargin = viewPix(5);
        UIButton *titleBtn = [UIButton buttonWithTitle:@" 订单信息" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@"订单详情-预约信息"];
        titleBtn.frame = CGRectMake(viewPix(32), viewPix(5), viewPix(200), viewPix(45));
        titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        titleBtn.userInteractionEnabled = NO;
        [headView addSubview:titleBtn];
        return headView;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return (section == 0)?0.01:viewPix(17);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if(section == 0){
        return [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }else{
        LGCornerFooterView *footView = [[LGCornerFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(17))];
        footView.backgroundColor = [UIColor clearColor];
        footView.bottomMargin = viewPix(5);
        return footView;
    }
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, topBarHeight, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGOrderSportGoodsCell class] forCellReuseIdentifier:@"goodsCell"];
        [_tableView registerClass:[LGOrderSportOrderCell class] forCellReuseIdentifier:@"orderCell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.headView;
    }
    return _tableView;
}

-(LGOrderSportHeadView *)headView{
    if(!_headView){
        _headView = [[LGOrderSportHeadView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(262))];
        _headView.title = @"订单类型：运动评估";
    }
    return _headView;
}


@end
